home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
borland
/
tpwn31.zip
/
PASCAL.ZIP
/
TOOLHELP.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-04-06
|
15KB
|
546 lines
{*******************************************************}
{ }
{ Turbo Pascal for Windows Run-time Library }
{ Windows 3.1 API Interface Unit }
{ }
{ Copyright (c) 1991 Borland International }
{ }
{*******************************************************}
unit TOOLHELP;
interface
uses WinTypes;
{ General symbols }
const
max_Data = 11;
max_Path = 255;
max_Module_Name = 8 + 1;
Max_ClassName = 255;
{ Global heap walking }
type
PGlobalInfo = ^TGlobalInfo;
TGlobalInfo = record
dwSize: Longint;
wcItems: Word;
wcItemsFree: Word;
wcItemsLRU: Word;
end;
PGlobalEntry = ^TGlobalEntry;
TGlobalEntry = record
dwSize: Longint;
dwAddress: Longint;
dwBlockSize: Longint;
hBlock: THandle;
wcLock: Word;
wcPageLock: Word;
wFlags: Word;
wHeapPresent: Bool;
hOwner: THandle;
wType: Word;
wData: Word;
dwNext: Longint;
dwNextAlt: Longint;
end;
const
{ GlobalFirst()/GlobalNext() flags }
global_All = 0;
global_LRU = 1;
global_Free = 2;
{ TGlobalEntry.wType entries }
gt_Unknown = 0;
gt_DGroup = 1;
gt_Data = 2;
gt_Code = 3;
gt_Task = 4;
gt_Resource = 5;
gt_Module = 6;
gt_Free = 7;
gt_Internal = 8;
gt_Sentinel = 9;
gt_BurgerMaster = 10;
{ If TGlobalEntry.wType = gt_Resource, the following is TGlobalEntry.wData: }
gd_UserDefined = 0;
gd_CursorComponent = 1;
gd_Bitmap = 2;
gd_IconComponent = 3;
gd_Menu = 4;
gd_Dialog = 5;
gd_String = 6;
gd_FontDir = 7;
gd_Font = 8;
gd_Accelerators = 9;
gd_RCData = 10;
gd_ErrTable = 11;
gd_Cursor = 12;
gd_Icon = 14;
gd_NameTable = 15;
gd_Max_Resource = 15;
{ TGlobalEntry.wFlags }
gf_PDB_Owner = $100; { Low byte us KERNAL flags }
function GlobalInfo(lpGlobalInfo: PGlobalInfo): Bool;
function GlobalFirst(lpGlobal: PGlobalEntry; wFlags: Word): Bool;
function GlobalNext(lpGlobal: PGlobalEntry; wFlags: Word): Bool;
function GlobalEntryHandle(lpGlobal: PGlobalEntry; hItem: THandle): Bool;
function GlobalEntryModule(lpGlobal: PGlobalEntry; hModule: THandle; wSeg: Word): Bool;
function GlobalHandleToSel(hMem: THandle): Word;
{ Local heap walking }
type
PLocalInfo = ^TLocalInfo;
TLocalInfo = record
dwSize: Longint;
wcItems: Word;
end;
PLocalEntry = ^TLocalEntry;
TLocalEntry = record
dwSize: Longint;
hHandle: THandle;
wAddress: Word;
wSize: Word;
wFlags: Word;
wcLock: Word;
wType: Word;
hHeap: Word;
wHeapType: Word;
wNext: Word;
end;
const
{ TLocalEntry.wHeapType flags }
Normal_Heap = 0;
User_Heap = 1;
gdi_Heap = 2;
{ TLocalEntry.wFlags }
lf_Fixed = 1;
lf_Free = 2;
lf_Moveable = 4;
{ TLocalEntry.wType }
lt_Normal = 0;
lt_Free = $FF;
lt_GDI_Pen = 1; { lt_GDI_* is for GDI's heap }
lt_GDI_Brush = 2;
lt_GDI_Font = 3;
lt_GDI_Palette = 4;
lt_GDI_Bitmap = 5;
lt_GDI_RGN = 6;
lt_GDI_DC = 7;
lt_GDI_Disabled_DC = 8;
lt_GDI_MetaDC = 9;
lt_GDI_MetaFile = 10;
lt_GDI_Max = lt_GDI_MetaFile;
lt_User_Class = 1; { lt_USER_* is for USER's heap }
lt_User_Wnd = 2;
lt_User_String = 3;
lt_User_Menu = 4;
lt_User_Clip = 5;
lt_User_CBox = 6;
lt_User_Palette = 7;
lt_User_ED = 8;
lt_User_BWL = 9;
lt_User_OwnerDraw = 10;
lt_User_SPB = 11;
lt_User_CheckPoint = 12;
lt_User_DCE = 13;
lt_User_MWP = 14;
lt_User_Prop = 15;
lt_User_LBIV = 16;
lt_User_Misc = 17;
lt_User_Atoms = 18;
lt_User_LockInputState = 19;
lt_User_HookList = 20;
lt_User_UserSeeUserDoAlloc = 21;
lt_User_HotKeyList = 22;
lt_User_PopUpMenu = 23;
lt_User_HandleTable = 32;
lt_User_Max = lt_User_HandleTable;
function LocalInfo(lpLocal: PLocalInfo; hHeap: THandle): Bool;
function LocalFirst(lpLocal: PLocalEntry; hHeap: THandle): Bool;
function LocalNext(lpLocal: PLocalEntry): Boolean;
{ Stack Tracing }
type
PStackTraceEntry = ^TStackTraceEntry;
TStackTraceEntry = record
dwSize: Longint;
hTask: THandle;
wSS: Word;
wBP: Word;
wCS: Word;
wIP: Word;
hModule: THandle;
wSegment: Word;
wFlags: Word;
end;
const
{ TStackTraceEntry.wFlags values }
frame_Far = 0;
frame_Near = 1;
function StackTraceFirst(lpStackTrace: PStackTraceEntry; hTask: THandle): Bool;
function StackTraceCSIPFirst(lpStackTrace: PStackTraceEntry;
wSS, wCS, wIP, wBP: Word): Bool;
function StackTraceNext(lpStackTrace: PStackTraceEntry): Bool;
{ Module list walking }
type
PModuleEntry = ^TModuleEntry;
TModuleEntry = record
dwSize: Longint;
szModule : array[0..max_Module_Name + 1] of Char;
hModule: THandle;
wUsageFlags: Word;
szExePath: array[0..max_Path + 1] of Char;
wNext: Word;
end;
function ModuleFirst(lpModule: PModuleEntry): Bool;
function ModuleNext(lpModule: PModuleEntry): Bool;
function ModuleFindName(lpModule: PModuleEntry; lpstrName: PChar): THandle;
function ModuleFindHandle(lpModule: PModuleEntry; hModule: THandle): THandle;
{ Task list walking }
type
PTaskEntry = ^TTaskEntry;
TTaskEntry = record
dwSize: Longint;
hTask: THandle;
hTaskParent: THandle;
hInst: THandle;
hModule: THandle;
wSS: Word;
wSP: Word;
wStackTop: Word;
wStackMinimum: Word;
wStackBottom: Word;
wcEvents: Word;
hQueue: THandle;
szModule: array[0..max_Module_Name + 1] of Char;
wPSPOffset: Word;
hNext: THandle;
end;
function TaskFirst(lpTask: PTaskEntry): Bool;
function TaskNext(lpTask: PTaskEntry): Bool;
function TaskFindHandle(lpTask: PTaskEntry; hTask: THandle): Bool;
function TaskSetCSIP(hTask: THandle; wCS, wIP: Word): Longint;
function TaskGetCSIP(hTask: THandle): Longint;
function TaskSwitch(hTask: THandle; dwNewCSIP: Longint): Bool;
{ Window Class enumeration }
type
PClassEntry = ^TClassEntry;
TClassEntry = record
dwSize: Longint;
hInst: THandle;
szClassName: array[0..Max_ClassName + 1] of Char;
wNext: Word;
end;
function ClassFirst(lpClass: PClassEntry): Bool;
function ClassNext(lpClass: PClassEntry): Bool;
type
{ Information functions }
PMemManInfo = ^TMemManInfo;
TMemManInfo = record
dwSize: Longint;
dwLargestFreeBlock: Longint;
dwMaxPagesAvailable: Longint;
dwMaxPagesLockable: Longint;
dwTotalLinearSpace: Longint;
dwTotalUnlockedPages: Longint;
dwFreePages: Longint;
dwTotalPages: Longint;
dwFreeLinearSpace: Longint;
dwSwapFilePages: Longint;
wPageSize: Word;
end;
function MemManInfo(lpEnhMode: PMemManInfo): Bool;
type
PSysHeapInfo = ^TSysHeapInfo;
TSysHeapInfo = record
dwSize: Longint;
wUserFreePercent: Word;
wGDIFreePercent: Word;
hUserSegment: THandle;
hGDISegment: THandle;
end;
function SystemHeapInfo(lpSysHeap: PSysHeapInfo): Bool;
{ Interrupt Handling }
const
{ Hooked interrupts }
int_Div0 = 0;
int_1 = 1;
int_3 = 3;
int_UDInstr = 6;
int_StkFault = 12;
int_GPFault = 13;
int_BadPageFault = 14;
int_CtlAltSysRq = 256;
{ TOOLHELP Interrupt callbacks registered with InterruptRegister should
* always be written in assembly language. The stack frame is not
* compatible with high level language conventions.
*
* This stack frame looks as follows to the callback. All registers
* should be preserved across this callback to allow restarting fault.
* ------------
* | Flags | [SP + 0Eh]
* | CS | [SP + 0Ch]
* | IP | [SP + 0Ah]
* | Handle | [SP + 08h]
* |Exception#| [SP + 06h]
* | AX | [SP + 04h] AX Saved to allow MakeProcInst